package com.shanling.shanlingcontroller.persenter

import android.content.Context
import com.shanling.shanlingcontroller.bean.FolderInfo
import com.shanling.shanlingcontroller.music.player.AppRepository
import com.shanling.shanlingcontroller.persenter.contract.FoldersContract
import com.shanling.shanlingcontroller.persenter.contract.ForgetContract
import com.shanling.shanlingcontroller.persenter.contract.SingerFragmentContract
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * Created by ch1 on 2019/11/22.
 */
class FoldersPersenter  constructor() : RxPresenter<FoldersContract.View>(), FoldersContract.Presenter {
    override fun loadFolders(context: Context) {
        mView?.showLoading()
        AppRepository.getFolderInfosRepository(context)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : Observer<List<FolderInfo>> {
                    override fun onSubscribe(d: Disposable) {
                    }

                    override fun onNext(folderInfos: List<FolderInfo>) {
                        if (mView==null){
                            return
                        }
                        mView.showFolders(folderInfos)
                        if (folderInfos.isEmpty()) {
                            mView.showEmptyView()
                        }
                        mView.hideLoading()
                    }
                    override fun onError(e: Throwable) {
                        if (mView==null){
                            return
                        }
                        mView.hideLoading()
                    }

                    override fun onComplete() {
                        if (mView==null){
                            return
                        }
                        mView.hideLoading()
                    }
                })

    }


}